/*
 * @Author: LinXunFeng linxunfeng@yeah.net
 * @Repo: https://github.com/LinXunFeng/flutter_scrollview_observer
 * @Date: 2022-09-27 22:46:36
 */

import 'package:bxultimate/app/theme/app_theme.dart';
import 'package:bxultimate/app/theme/gaps.dart';
import 'package:bxultimate/data/store/config_store.dart';
import 'package:bxultimate/domain/application/organization/ChatDto.dart';
import 'package:bxultimate/domain/application/organization/chat_model.dart';
import 'package:bxultimate/widgets/mk_load_image.dart';
import 'package:flutter/material.dart';

class ChatItemWidget extends StatelessWidget {
  const ChatItemWidget({
    Key? key,
    required this.chatModel,
    required this.index,
    required this.itemCount,
    this.onRemove,
  }) : super(key: key);

  final ChatDto chatModel;
  final int index;
  final int itemCount;
  final Function? onRemove;

  @override
  Widget build(BuildContext context) {
    final isOwn = chatModel.type == 1;
    final nickName = chatModel.sendUserName!;
    Widget resultWidget = Row(
      textDirection: isOwn ? TextDirection.ltr : TextDirection.rtl,
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        ClipRRect(
          borderRadius: BorderRadius.circular(20),
          child: MkLoadImage(
            ConfigStore.to.baseFileUrl + chatModel.sendUserheadImg!,
            width: 40,
            height: 40,
          ),
        ),
        const SizedBox(width: 10),
        Expanded(
          child: Container(
            padding: const EdgeInsets.all(10),
            decoration: BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.circular(4),
            ),
            child: Column(
              mainAxisAlignment: MainAxisAlignment.start,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  '${chatModel.taskFileName}',
                  style: const TextStyle(
                    fontSize: 14,
                    fontWeight: FontWeight.w500,
                  ),
                ),
                Gaps.vGap8,
                Text(
                  '${chatModel.taskFileDesc}',
                  style: TextStyle(color: Color(0xFF606266),fontSize: 12),
                ),
                Gaps.vGap8,
                Text(
                  '${chatModel.submitDate}',
                  style: TextStyle(color: Color(0xFF606266),fontSize: 10),
                ),

                Divider(),
                Row(
                  crossAxisAlignment: CrossAxisAlignment.end,
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Expanded(
                        child: Center(child: Text('未完成 (${chatModel.finishNum})',style: TextStyle(color: Colors.redAccent,fontSize: 12),))),
                    Expanded(
                        child: Center(child: Text('已完成 (${chatModel.finishNum})',style: TextStyle(color: Colors.blue,fontSize: 12),))),

                  ],
                )

              ],
            ),
          ),
        ),
        const SizedBox(width: 50),
      ],
    );
    resultWidget = Column(
      children: [
        resultWidget,
        const SizedBox(height: 15),
      ],
    );
    // resultWidget = Dismissible(
    //   key: UniqueKey(),
    //   child: resultWidget,
    //   onDismissed: (_) {
    //     onRemove?.call();
    //   },
    // );
    return resultWidget;
  }
}
